package com.yoona.system.controller;
import com.yoona.common.auth.CheckLogin;
import com.yoona.common.response.BaseResponse;
import com.yoona.log.persistence.MyLog;
import com.yoona.system.dto.SysUserLoginOrRegisterDto;
import com.yoona.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Email: m15602498163@163.com
 * @Author: yoonada
 * @Date: 2020/9/21
 * @Time: 7:49 下午
 * @Msg:
 */
@Api(tags = "系统用户")
@CrossOrigin
@RestController
@RequestMapping("/sys-user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysUserController {

    private final ISysUserService sysUserService;

    @ApiOperation("获取用户微信的appId")
    @PostMapping("/getOpenId")
    public BaseResponse<Object> getOpenId(String code) throws Exception {
        return sysUserService.getOpenId(code);
    }

    @ApiOperation("登录/注册")
    @PostMapping(value = "/loginOrRegister")
    public BaseResponse<Object> loginOrRegister(@RequestBody SysUserLoginOrRegisterDto sysUserLoginOrRegisterDto){
        return sysUserService.loginOrRegister(sysUserLoginOrRegisterDto);
    }

    @ApiOperation("微信登录")
    @PostMapping(value = "/wxLogin")
    public BaseResponse<Object> wxLogin(String code) throws Exception {
        return sysUserService.wxLogin(code);
    }

    @MyLog("获取个人信息")
    @CheckLogin
    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public BaseResponse<Object> getUserInfo(){
        return sysUserService.getUserInfo();
    }

}
